package cn.otrue.patienthealthmanager.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间工具类
 * 
 * @author zhangwenjun
 * 
 */
public class MyDateUtils {
	/**
	 * 获取当天的开始时间
	 * @param date
	 * @return
	 */
	public static Date getDateBeginTime(Date date) {
		try {
			String timeStr = new SimpleDateFormat("yyyy-MM-dd").format(date);
			Date retDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
					.parse(timeStr + " 00:00:00");
			return retDate;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	/**
	 * 获取当天的结束时间
	 * @param date
	 * @return
	 */
	public static Date getDateEndTime(Date date) {
		try {
			String timeStr = new SimpleDateFormat("yyyy-MM-dd").format(date);
			Date retDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
					.parse(timeStr + " 23:59:59");
			return retDate;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static Date parseDate(String dateStr,String format){
		try {
			Date date=new SimpleDateFormat(format).parse(dateStr);
			return date;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	public static String addDays(Date date,int days){
        date.setTime(date.getTime()+24*60*60*1000*days);
        return DateFormatUtils.format(date, "yyyy-MM-dd");
	}
}
